package com.example.takeaway.serivce.impl;

import java.util.List;
import java.util.Map;

import com.alipay.api.AlipayApiException;
import com.example.takeaway.entity.AlipayBean;
import com.example.takeaway.entity.Goods;
import com.example.takeaway.entity.Orders;
import com.example.takeaway.mapper.OrderdetailMapper;
import com.example.takeaway.mapper.OrdersMapper;
import com.example.takeaway.serivce.AlipayService;
import com.example.takeaway.serivce.IOrdersService;
import com.example.takeaway.utils.PageResult;
import com.example.takeaway.utils.PageUtils;
import com.example.takeaway.utils.PassToken;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;


/**
 * ordersService业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-15
 */
@Service
public class OrdersServiceImpl implements IOrdersService
{
    @Autowired
    private OrdersMapper ordersMapper;
    @Autowired
    private OrderdetailMapper orderdetailMapper;

    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout = 6000,rollbackFor = Exception.class)

    /**
     * 查询orders
     * 
     * @param orderid orders主键
     * @return orders
     */
    @Override
    public Orders selectOrdersByOrderid(Long orderid)
    {
        return ordersMapper.selectOrdersByOrderid(orderid);
    }

    /**
     * 查询orders列表
     * 
     * @param orders orders
     * @return orders
     */
    @Override
    public PageResult selectOrdersList(Orders orders,int pageNum, int pageSize)
    {
        PageHelper.startPage(pageNum,pageSize);
        List<Orders> list = ordersMapper.selectOrdersList(orders);
        PageInfo<Orders> pageInfo = new PageInfo<>(list);
        PageResult pageResult = PageUtils.getPageResult(pageInfo);
        return pageResult;
    }

    @Override
    public Orders getOrdersByOrdersn(String ordersn) {
        return ordersMapper.getOrdersByOrdersn(ordersn);
    }

    /**
     * 新增orders
     * 
     * @param orders orders
     * @return 结果
     */
    @Override
    public int insertOrders(Orders orders)
    {
        int i =ordersMapper.insertOrders(orders);
        if(i>0){
            int j = orderdetailMapper.insertOrderdetails(orders.getOrderdetailsList());
            if(j>0){
                return 1;
            }else {
                return 0;
            }
        }else{
            return 0;
        }
    }

    /**
     * 修改orders
     * 
     * @param orders orders
     * @return 结果
     */
    @Override
    public int updateOrders(Orders orders)
    {
        return ordersMapper.updateOrders(orders);
    }

    /**
     * 批量删除orders
     * 
     * @param orderids 需要删除的orders主键
     * @return 结果
     */
    @Override
    public int deleteOrdersByOrderids(Long[] orderids)
    {
        return ordersMapper.deleteOrdersByOrderids(orderids);
    }

    /**
     * 删除orders信息
     * 
     * @param orderid orders主键
     * @return 结果
     */
    @Override
    public int deleteOrdersByOrderid(Long orderid)
    {
        return ordersMapper.deleteOrdersByOrderid(orderid);
    }



}
